<?php

namespace App\Admin\Extensions;

use App\Models\GoldRecord;
use App\Models\User;
use App\Models\Order;
use App\Models\Product;
use App\Models\VipPurchase;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Layout\Column;

class DashboardList
{
	public function newRecordsList()
	{
		return function (Row $row) {
			$this->newUsersList($row, 3);
			$this->newProductsList($row, 3);
			$this->newOrdersList($row, 3);
			$this->newGoldRecordsList($row, 3);
		};
	}
	
	protected function newUsersList(Row $row, $column)
	{
		$row->column((int)$column, function (Column $column) {
			$newUsers = User::query()->orderByDesc('id')->take(10)->get();
			$column->append(new Box('最新用户', view('admin.home.newUsers', ['users' => $newUsers])));
		});
	}
	
	protected function newProductsList(Row $row, $column)
	{
		$row->column((int)$column, function (Column $column) {
			$newProducts = Product::query()->orderByDesc('id')->take(10)->get();
			$column->append(new Box('最新商品', view('admin.home.newProducts', ['products' => $newProducts])));
		});
	}
	
	protected function newOrdersList(Row $row, $column)
	{
		$row->column((int)$column, function (Column $column) {
			$newOrders = Order::query()->whereNotNull('paid_at')->orderByDesc('id')->take(10)->get();
			$column->append(new Box('最新商品订单', view('admin.home.newOrders', ['orders' => $newOrders])));
		});
	}
	
	protected function newGoldRecordsList(Row $row, $column)
	{
		$row->column((int)$column, function (Column $column) {
			$newGoldRecords = GoldRecord::query()->whereNotNull('paid_at')->orderByDesc('id')->take(10)->get();
			$column->append(new Box('最新抢购记录', view('admin.home.newGoldRecords', ['records' => $newGoldRecords])));
		});
	}
	
	
}
